﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
 
using System.Security.Permissions;
using Microsoft.Win32;

namespace UI
{
    public partial class FrmSelectFiles : Form
    {
       

        OpenFileDialog dialog = new OpenFileDialog();
        FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();

        public FrmSelectFiles()
        {
            InitializeComponent();

            this.comboBox1.DropDownStyle = ComboBoxStyle.DropDownList;
             
            dialog = new OpenFileDialog();
            dialog.Multiselect = true;

            if (Selection != null && Selection.Length>0)
            {
                string[] paths = Selection.Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries);

                
                for (int s = 0; s < paths.Count(); s++ )
                {
                    this.comboBox1.Items.Add(paths[s]);
                   
                }
                this.comboBox1.Text = paths[0];

                 
            }
        }

        private void richTextBox1_TextChanged(object sender, EventArgs e)
        {

        }
        public string Selection
        {
            get
            {

                return Properties.Settings.Default.FileSelection;
            }
            set
            {
                Properties.Settings.Default.FileSelection = value;

                Properties.Settings.Default.Save();
            }
        }

       
        public string InitialDirectory
        {
            set
            {
                dialog.InitialDirectory = value;
            }
        }
         
         

        private void comboBox1_DropDown(object sender, EventArgs e)
        {

        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (System.IO.Directory.Exists(Properties.Settings.Default.Button1Path))
            {
                folderBrowserDialog1.SelectedPath = Properties.Settings.Default.Button1Path;
            }
            DialogResult result = folderBrowserDialog1.ShowDialog();

            if (result == DialogResult.OK)
            {
                string folderName = folderBrowserDialog1.SelectedPath;

                comboBox1.Items.Add(folderName);
                comboBox1.Text = folderName;

                Selection += folderName.ToString() + ',';

                Properties.Settings.Default.Button1Path = folderBrowserDialog1.SelectedPath;

                Properties.Settings.Default.Save();

            }
        }
        private void button2_Click_1(object sender, EventArgs e)
        {
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                foreach (string s in dialog.FileNames)
                {
                    comboBox1.Items.Add(s);
                    comboBox1.Text = s;

                    Selection += s.ToString() + ',';

                    Properties.Settings.Default.button2Path = s;

                    Properties.Settings.Default.Save();
                }
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Close();
        }
        
        
        public event EventHandler MyFormClosing;
        
        private void FrmSelectFiles_FormClosing_1(object sender, FormClosingEventArgs e)
        {
            if (MyFormClosing != null)
            {
                this.MyFormClosing(sender, e);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.comboBox1.Items.Clear();
            Selection = String.Empty;
        }
    }
}
